{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "92e89f2e-ae80-4f1c-9caa-68f5b11650b0",
   "metadata": {},
   "source": [
    "由于用户注销账户，可能会导致其下面的仓库没有人维护，"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "678e1314-3b66-4273-b791-712122946456",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "请帮我检查特定组织所有仓库的成员是否为空，如果为空，则设置特定成员给该仓库。\n",
    "\n",
    "1、接口1：获取特定组织下面的仓库列表\n",
    "- 接口地址：https://atomgit.com/api/project/v1/list/org\n",
    "- post格式，post body {orgCode: \"mycareerlearnhub\", page: 0, pageSize: 1000}\n",
    "- response 响应\n",
    "{\n",
    "    \"amount\": 32,\n",
    "    \"totalPage\": 2,\n",
    "    \"page\": 1,\n",
    "    \"pageSize\": 20,\n",
    "    \"list\": [\n",
    "        {\n",
    "            \"id\": 36204967,\n",
    "            \"name\": \"build-your-own-x\",\n",
    "            \"path\": \"build-your-own-x\",\n",
    "            \"description\": \"Master programming by recreating your favorite technologies from scratch.\",\n",
    "            \"pathWithNamespace\": \"mycareerlearnhub/build-your-own-x\",\n",
    "            \"nameWithNamespace\": \"mycareerlearnhub / build-your-own-x\",\n",
    "            \"lastActivityAt\": \"2024-06-26 17:51:54\",\n",
    "            \"visibilityLevel\": 20,\n",
    "            \"starCount\": 0,\n",
    "            \"forkCount\": 0,\n",
    "            \"webUrl\": \"https://atomgit.com/mycareerlearnhub/build-your-own-x\",\n",
    "            \"avatarUrl\": null,\n",
    "            \"createdAt\": \"2024-06-26 17:51:54\",\n",
    "            \"stared\": false,\n",
    "            \"isSelected\": false,\n",
    "            \"issueCount\": 0,\n",
    "            \"archived\": false,\n",
    "            \"license\": null,\n",
    "            \"organizationId\": null,\n",
    "            \"belongTo\": \"65e929d19422eb2718f05850\",\n",
    "            \"repositorySize\": \"6.26367\",\n",
    "            \"httpUrlToRepo\": \"https://atomgit.com/mycareerlearnhub/build-your-own-x.git\",\n",
    "            \"sshUrlToRepo\": \"git@atomgit.com:mycareerlearnhub/build-your-own-x.git\",\n",
    "            \"creatorId\": null,\n",
    "            \"defaultBranch\": null\n",
    "        }]\n",
    "}\n",
    "\n",
    "2、接口2：获取特定仓库的成员列表\n",
    "- 接口地址：https://atomgit.com/api/v4/projects/{repo_id}/all_members?_input_charset=utf-8，其中 repo_id 来自上一个接口的返回值 list 下面的 id\n",
    "- get 格式\n",
    "- response 响应，如果响应为空，则表示没有成员，就需要调用接口3为其添加成员\n",
    "[\n",
    "    {\n",
    "        \"access_level\": 40,\n",
    "        \"avatar_url\": \"https://file.atomgit.com/uploads/user/1698197408152_6706.jpeg\",\n",
    "        \"confirmed\": true,\n",
    "        \"email\": \"xuchenyang@openatom.org\",\n",
    "        \"expire_at\": null,\n",
    "        \"extern_uid\": \"649a75c5d30b2b0d3de9086e\",\n",
    "        \"id\": 27654,\n",
    "        \"inherited\": null,\n",
    "        \"member_type\": \"USERS\",\n",
    "        \"name\": \"tianchang\",\n",
    "        \"related_infos\": [],\n",
    "        \"state\": \"active\",\n",
    "        \"sync_by_current_source\": false,\n",
    "        \"tb_user_id\": \"649a75c5d30b2b0d3de9086e\",\n",
    "        \"username\": \"tianchang\",\n",
    "        \"web_url\": \"\"\n",
    "    }\n",
    "]\n",
    "\n",
    "3、接口3：为特定仓库添加特定成员, \"_userId\": \"663aeca058547a2147a9bb8a\",\n",
    "- 接口地址：https://atomgit.com/api/v4/projects/33381673/membersV4?_input_charset=utf-8\n",
    "- post格式，post body {member_info_list: [{extern_uid: \"663aeca058547a2147a9bb8a\", member_type: \"USERS\"}], access_level: 40}，其中这个【extern_uid: \"663aeca058547a2147a9bb8a\"】就是一个固定值 \n",
    "- response 响应\n",
    "{\n",
    "  \"access_level\": 40,\n",
    "  \"avatar_url\": \"https://file.atomgit.com/uploads/user/1715138065788_2106.jpeg\",\n",
    "  \"expire_at\": null,\n",
    "  \"extern_uid\": \"663aeca058547a2147a9bb8a\",\n",
    "  \"id\": 124533,\n",
    "  \"member_type\": \"USERS\",\n",
    "  \"name\": \"开源小兵\",\n",
    "  \"state\": \"active\",\n",
    "  \"tb_user_id\": \"663aeca058547a2147a9bb8a\",\n",
    "  \"username\": \"kaiyuanxiaobing\",\n",
    "  \"web_url\": \"\"\n",
    "}\n",
    "\n",
    "\n",
    "注意，接口的header可以这样获取。\n",
    "def load_headers():\n",
    "    try:\n",
    "        with open('header.json', 'r', encoding='utf-8') as f:\n",
    "            headers = json.load(f)\n",
    "        print(\"[OK] Headers loaded successfully from header.json.\")\n",
    "        return headers\n",
    "    except Exception as e:\n",
    "        print(f\"[Failed] Failed to load headers from header.json. Error: {e}\")\n",
    "        return {}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9a7b7070-fbab-443c-a9bb-bb2813e25179",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[OK] Headers loaded successfully from header.json.\n",
      "Checking repository: build-your-own-x (ID: 36204967)\n",
      "https://atomgit.com/api/v4/projects/36204967/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786710946023e39f6\"}\n",
      "build-your-own-x\n",
      "Checking repository: learngit (ID: 33381575)\n",
      "https://atomgit.com/api/v4/projects/33381575/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786712464084e39e4\"}\n",
      "learngit\n",
      "Checking repository: git-learning-course (ID: 34062624)\n",
      "https://atomgit.com/api/v4/projects/34062624/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786713948453e39d1\"}\n",
      "git-learning-course\n",
      "Checking repository: markdown-course (ID: 34062650)\n",
      "https://atomgit.com/api/v4/projects/34062650/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786715626029e39f6\"}\n",
      "markdown-course\n",
      "Checking repository: reference (ID: 33381782)\n",
      "https://atomgit.com/api/v4/projects/33381782/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786717126400e39f3\"}\n",
      "reference\n",
      "Checking repository: leetcode (ID: 33381674)\n",
      "https://atomgit.com/api/v4/projects/33381674/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786718688638e39be\"}\n",
      "leetcode\n",
      "Checking repository: GOFamily (ID: 33381673)\n",
      "https://atomgit.com/api/v4/projects/33381673/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786720227677e39f8\"}\n",
      "GOFamily\n",
      "Checking repository: hello-algo (ID: 33381599)\n",
      "https://atomgit.com/api/v4/projects/33381599/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786721814117e39fb\"}\n",
      "hello-algo\n",
      "Checking repository: JAVA面试资料 (ID: 33381374)\n",
      "https://atomgit.com/api/v4/projects/33381374/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786723258652e39be\"}\n",
      "JAVA面试资料\n",
      "Checking repository: tips_for_interview (ID: 33381370)\n",
      "https://atomgit.com/api/v4/projects/33381370/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786724764123e39fb\"}\n",
      "tips_for_interview\n",
      "Checking repository: ops_doc (ID: 33381369)\n",
      "https://atomgit.com/api/v4/projects/33381369/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786726324127e39fb\"}\n",
      "ops_doc\n",
      "Checking repository: linux-tutorial (ID: 33381368)\n",
      "https://atomgit.com/api/v4/projects/33381368/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786727746921e39d7\"}\n",
      "linux-tutorial\n",
      "Checking repository: linux (ID: 33381367)\n",
      "https://atomgit.com/api/v4/projects/33381367/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786729286435e3a06\"}\n",
      "linux\n",
      "Checking repository: kjyw (ID: 33381366)\n",
      "https://atomgit.com/api/v4/projects/33381366/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786730772969e3a07\"}\n",
      "kjyw\n",
      "Checking repository: CS-Job-Guide (ID: 33381365)\n",
      "https://atomgit.com/api/v4/projects/33381365/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786732256441e3a06\"}\n",
      "CS-Job-Guide\n",
      "Checking repository: Books (ID: 33381364)\n",
      "https://atomgit.com/api/v4/projects/33381364/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786733704137e39fb\"}\n",
      "Books\n",
      "Checking repository: Awsome-Front-End-learning-resource (ID: 33381363)\n",
      "https://atomgit.com/api/v4/projects/33381363/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786735296062e39f6\"}\n",
      "Awsome-Front-End-learning-resource\n",
      "Checking repository: Introduction-to-Golang (ID: 33381358)\n",
      "https://atomgit.com/api/v4/projects/33381358/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786736854152e39e4\"}\n",
      "Introduction-to-Golang\n",
      "Checking repository: funNLP (ID: 33381357)\n",
      "https://atomgit.com/api/v4/projects/33381357/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786738478687e39be\"}\n",
      "funNLP\n",
      "Checking repository: awesome-cs-books (ID: 33381356)\n",
      "https://atomgit.com/api/v4/projects/33381356/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786739908475e39d1\"}\n",
      "awesome-cs-books\n",
      "Checking repository: awesome-c-cn (ID: 33381355)\n",
      "https://atomgit.com/api/v4/projects/33381355/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786741475718e3a05\"}\n",
      "awesome-c-cn\n",
      "Checking repository: fe-interview (ID: 33381353)\n",
      "https://atomgit.com/api/v4/projects/33381353/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786743166948e39d7\"}\n",
      "fe-interview\n",
      "Checking repository: awesome-programming-books (ID: 33381352)\n",
      "https://atomgit.com/api/v4/projects/33381352/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786744606459e3a06\"}\n",
      "awesome-programming-books\n",
      "Checking repository: vue_code_parsing (ID: 33381351)\n",
      "https://atomgit.com/api/v4/projects/33381351/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786746077745e39f8\"}\n",
      "vue_code_parsing\n",
      "Checking repository: linux_kernel_wiki (ID: 33381349)\n",
      "https://atomgit.com/api/v4/projects/33381349/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786747522993e3a07\"}\n",
      "linux_kernel_wiki\n",
      "Checking repository: linux-source-code-analyze (ID: 33381348)\n",
      "https://atomgit.com/api/v4/projects/33381348/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786748952998e3a07\"}\n",
      "linux-source-code-analyze\n",
      "Checking repository: linux-insides-zh (ID: 33381347)\n",
      "https://atomgit.com/api/v4/projects/33381347/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786750366090e39f6\"}\n",
      "linux-insides-zh\n",
      "Checking repository: front-end-rss (ID: 33381346)\n",
      "https://atomgit.com/api/v4/projects/33381346/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786751753001e3a07\"}\n",
      "front-end-rss\n",
      "Checking repository: GitHub-Chinese-Top-Charts (ID: 33381342)\n",
      "https://atomgit.com/api/v4/projects/33381342/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786753344177e39e4\"}\n",
      "GitHub-Chinese-Top-Charts\n",
      "Checking repository: Vue3_introduction (ID: 33381340)\n",
      "https://atomgit.com/api/v4/projects/33381340/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786754928617e39cf\"}\n",
      "Vue3_introduction\n",
      "Checking repository: linux-command (ID: 33381338)\n",
      "https://atomgit.com/api/v4/projects/33381338/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786756818711e39be\"}\n",
      "linux-command\n",
      "Checking repository: learnGitBranching (ID: 33381330)\n",
      "https://atomgit.com/api/v4/projects/33381330/all_members?_input_charset=utf-8\n",
      "[Failed] Failed to get repository members. Status code: 403, response: {\"cause\":\"访问的资源无权限!\",\"errorCode\":\"SYSTEM_FORBIDDEN_ERROR\",\"message\":\"禁止访问\",\"pushRuleExist\":false,\"status\":false,\"traceId\":\"0b6e703e17195786758266098e39f6\"}\n",
      "learnGitBranching\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import json\n",
    "\n",
    "def load_headers():\n",
    "    try:\n",
    "        with open('header.json', 'r', encoding='utf-8') as f:\n",
    "            headers = json.load(f)\n",
    "        print(\"[OK] Headers loaded successfully from header.json.\")\n",
    "        return headers\n",
    "    except Exception as e:\n",
    "        print(f\"[Failed] Failed to load headers from header.json. Error: {e}\")\n",
    "        return {}\n",
    "\n",
    "def get_repositories(org_code, headers):\n",
    "    url = 'https://atomgit.com/api/project/v1/list/org'\n",
    "    payload = {\n",
    "        'orgCode': org_code,\n",
    "        'page': 0,\n",
    "        'pageSize': 1000\n",
    "    }\n",
    "    response = requests.post(url, headers=headers, json=payload)\n",
    "    if response.status_code == 200:\n",
    "        return response.json()['list']\n",
    "    else:\n",
    "        print(f\"[Failed] Failed to get repositories. Status code: {response.status_code}, response: {response.text}\")\n",
    "        return []\n",
    "\n",
    "def get_repo_members(repo_id, headers):\n",
    "    url = f'https://atomgit.com/api/v4/projects/{repo_id}/all_members?_input_charset=utf-8'\n",
    "    print(url)\n",
    "    response = requests.get(url)\n",
    "    if response.status_code == 200:\n",
    "        return response.json()\n",
    "    else:\n",
    "        print(f\"[Failed] Failed to get repository members. Status code: {response.status_code}, response: {response.text}\")\n",
    "        return []\n",
    "\n",
    "def add_member_to_repo(repo_id, extern_uid):\n",
    "    url = f'https://atomgit.com/api/v4/projects/{repo_id}/membersV4?_input_charset=utf-8'\n",
    "    payload = {\n",
    "        'member_info_list': [{'extern_uid': extern_uid, 'member_type': 'USERS'}],\n",
    "        'access_level': 40\n",
    "    }\n",
    "    response = requests.post(url, headers=headers, json=payload)\n",
    "    if response.status_code == 200:\n",
    "        print(f\"[OK] Successfully added member {extern_uid} to repository {repo_id}.\")\n",
    "        return response.json()\n",
    "    else:\n",
    "        print(f\"[Failed] Failed to add member to repository. Status code: {response.status_code}, response: {response.text}\")\n",
    "        return None\n",
    "\n",
    "def main():\n",
    "    org_code = \"mycareerlearnhub\"\n",
    "    extern_uid = \"663aeca058547a2147a9bb8a\"\n",
    "\n",
    "    # Load headers\n",
    "    headers = load_headers()\n",
    "\n",
    "    # Get list of repositories\n",
    "    repositories = get_repositories(org_code, headers)\n",
    "    # print(repositories)\n",
    "\n",
    "    for repo in repositories:\n",
    "        repo_id = repo['id']\n",
    "        repo_name = repo['name']\n",
    "        print(f\"Checking repository: {repo_name} (ID: {repo_id})\")\n",
    "\n",
    "        # Get repository members\n",
    "        members = get_repo_members(repo_id, headers)\n",
    "        print(repo_name)\n",
    "        \n",
    "        # If no members, add the specified member\n",
    "        # if not members:\n",
    "        #     print(f\"[Info] No members found in repository {repo_name}. Adding member...\")\n",
    "        #     add_member_to_repo(repo_id, extern_uid)\n",
    "        # else:\n",
    "        #     print(f\"[Info] Repository {repo_name} already has members. No action needed.\")\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    main()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f23ce13f-fc4f-49c3-a8be-6b7fafe540a2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
